package org.nowcoder.huawei.c100;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;

/**
 * 57:游戏分组/英雄联盟
 */
public class HC057 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int[] nums = new int[input.length];
        for (int i = 0; i < input.length; i++) {
            nums[i] = Integer.parseInt(input[i]);
        }
        int sum = Arrays.stream(nums).sum();
        boolean[] uesd = new boolean[nums.length];
        Arrays.sort(nums);
        new HC057().solve(nums, uesd, sum);
    }

    private LinkedList<Integer> path = new LinkedList<>();
    private int min = Integer.MAX_VALUE;

    public void solve(int[] nums, boolean[] used, int sum) {
        if (path.size() == 5) {
            int var1 = 0;
            for (int i : path) {
                var1 += i;
            }
            int var2 = sum - var1;
            min = Math.min(min, Math.abs(var1 - var2));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (used[i]) {
                continue;
            }
            if (i > 0 && nums[i] == nums[i - 1] && !used[i - 1]) {
                continue;
            }
            path.add(nums[i]);
            used[i] = true;
            solve(nums, used, sum);
            path.removeLast();
            used[i] = false;
        }
    }
}
